home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / ziodev2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.8 KB  |  131 lines

  1. /* Copyright (C) 1993, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: ziodev2.c,v 1.3 2000/09/19 19:00:54 lpd Exp $ */
  20. /* (Level 2) IODevice operators */
  21. #include "string_.h"
  22. #include "ghost.h"
  23. #include "gp.h"
  24. #include "oper.h"
  25. #include "stream.h"
  26. #include "gxiodev.h"
  27. #include "dstack.h"        /* for systemdict */
  28. #include "files.h"        /* for file_open_stream */
  29. #include "iparam.h"
  30. #include "iutil2.h"
  31. #include "store.h"
  32.  
  33. /* ------ %null% ------ */
  34.  
  35. /* This represents the null output file. */
  36. private iodev_proc_open_device(null_open);
  37. const gx_io_device gs_iodev_null = {
  38.     "%null%", "Special",
  39.     {
  40.     iodev_no_init, null_open, iodev_no_open_file,
  41.     iodev_os_fopen, iodev_os_fclose,
  42.     iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  43.     iodev_no_enumerate_files, NULL, NULL,
  44.     iodev_no_get_params, iodev_no_put_params
  45.     }
  46. };
  47.  
  48. private int
  49. null_open(gx_io_device * iodev, const char *access, stream ** ps,
  50.       gs_memory_t * mem)
  51. {
  52.     if (!streq1(access, 'w'))
  53.     return_error(e_invalidfileaccess);
  54.     return file_open_stream(gp_null_file_name,
  55.                 strlen(gp_null_file_name),
  56.                 access, 256 /* arbitrary */ , ps,
  57.                 iodev->procs.fopen, mem);
  58. }
  59.  
  60. /* ------ Operators ------ */
  61.  
  62. /* <iodevice> .getdevparams <mark> <name> <value> ... */
  63. private int
  64. zgetdevparams(i_ctx_t *i_ctx_p)
  65. {
  66.     os_ptr op = osp;
  67.     gx_io_device *iodev;
  68.     stack_param_list list;
  69.     gs_param_list *const plist = (gs_param_list *) & list;
  70.     int code;
  71.     ref *pmark;
  72.  
  73.     check_read_type(*op, t_string);
  74.     iodev = gs_findiodevice(op->value.bytes, r_size(op));
  75.     if (iodev == 0)
  76.     return_error(e_undefinedfilename);
  77.     stack_param_list_write(&list, &o_stack, NULL, iimemory);
  78.     if ((code = gs_getdevparams(iodev, plist)) < 0) {
  79.     ref_stack_pop(&o_stack, list.count * 2);
  80.     return code;
  81.     }
  82.     pmark = ref_stack_index(&o_stack, list.count * 2);
  83.     make_mark(pmark);
  84.     return 0;
  85. }
  86.  
  87. /* <mark> <name> <value> ... <iodevice> .putdevparams */
  88. private int
  89. zputdevparams(i_ctx_t *i_ctx_p)
  90. {
  91.     os_ptr op = osp;
  92.     gx_io_device *iodev;
  93.     stack_param_list list;
  94.     gs_param_list *const plist = (gs_param_list *) & list;
  95.     int code;
  96.     password system_params_password;
  97.  
  98.     check_read_type(*op, t_string);
  99.     iodev = gs_findiodevice(op->value.bytes, r_size(op));
  100.     if (iodev == 0)
  101.     return_error(e_undefinedfilename);
  102.     code = stack_param_list_read(&list, &o_stack, 1, NULL, false, iimemory);
  103.     if (code < 0)
  104.     return code;
  105.     code = dict_read_password(&system_params_password, systemdict,
  106.                   "SystemParamsPassword");
  107.     if (code < 0)
  108.     return code;
  109.     code = param_check_password(plist, &system_params_password);
  110.     if (code != 0) {
  111.     iparam_list_release(&list);
  112.     return_error(code < 0 ? code : e_invalidaccess);
  113.     }
  114.     code = gs_putdevparams(iodev, plist);
  115.     iparam_list_release(&list);
  116.     if (code < 0)
  117.     return code;
  118.     ref_stack_pop(&o_stack, list.count * 2 + 2);
  119.     return 0;
  120. }
  121.  
  122. /* ------ Initialization procedure ------ */
  123.  
  124. const op_def ziodev2_l2_op_defs[] =
  125. {
  126.     op_def_begin_level2(),
  127.     {"1.getdevparams", zgetdevparams},
  128.     {"2.putdevparams", zputdevparams},
  129.     op_def_end(0)
  130. };
  131.